#ifndef _LRU_H
#define _LRU_H

#include <ds/list.h>
#include <ds/mutex.h>

typedef struct lru {
    lnode_t head;
    size_t size;
    mutex_t lock;
    int (*destory)(lnode_t*); // called when evict, return 1 if success, 0 if fail
} lru_t;

lru_t* lru_init(int (*destory)(lnode_t*));

void lru_use_one(lru_t* lru, lnode_t* elem);

void lru_evict_one(lru_t* lru);

void lru_remove(lru_t* lru, lnode_t* elem);

void lru_evict_half(lru_t* lru);

void lru_evict_count(lru_t* lru, size_t count);

bool lru_must_evict(lru_t* lru, size_t count);

#endif /* _LRU_H */